import moment from 'moment'

/* ---------- 应用函数，辅助计算 ---------- */
//在6min间隔情况下，将目标传入时间向下取整为6min的倍数
export function floorTo6min (time) {
  let now_time = moment(time).format('YYYY-MM-DD HH');
  let minutes = moment(time).format('mm');
  let renderminutes;
  if (minutes % 6 === 0) {
    renderminutes = minutes
  } else {
    renderminutes = Math.floor(minutes / 6) * 6;
  }
  return now_time + ':' + renderminutes
}

//计算是否为整数点
export function isHour (startTime, minutesToAdd, isAdd = true) {
  // 创建初始日期时间对象
  let initialDateTime = moment(startTime, 'YYYY-MM-DD HH:mm:ss');
  // 加上指定的分钟数
  let newDateTime = isAdd ? initialDateTime.add(minutesToAdd, 'minutes') : initialDateTime.subtract(minutesToAdd, 'minutes');
  // 判断是否为整点
  let isOnTheHour = newDateTime.minute() === 0 && newDateTime.second() === 0;
  // 返回1表示整点，返回0表示不是整点
  return isOnTheHour ? 1 : 0;
}

//计算是否为当天的0点
export function isDay (startTime, hoursToAdd, isAdd = true) {
  let initialDateTime = moment(startTime, 'YYYY-MM-DD HH');
  let newDateTime = isAdd ? initialDateTime.add(hoursToAdd, 'hours').format('YYYY-MM-DD HH') : initialDateTime.subtract(hoursToAdd, 'hours').format('YYYY-MM-DD HH');
  let midnight = moment(newDateTime).startOf('day').format('YYYY-MM-DD HH');
  return newDateTime === midnight ? 1 : 0;
}

//计算是否为当月的第一天
export function isMonth (startTime, daysToAdd) {
  let initialDateTime = moment(startTime, 'YYYY-MM-DD');
  let newDateTime = initialDateTime.add(daysToAdd, 'days').format('YYYY-MM-DD');
  let firstDay = moment(newDateTime).startOf('month').format('YYYY-MM-DD');
  return newDateTime === firstDay ? 1 : 0;
}

// 传入间隔 计算一个1个小格是多久
export function calcSteps (step_str) {
  if (step_str == 'step_6min') {
    return 6
  } else if (step_str == 'step_10min') {
    return 10
  } else if (step_str == 'step_1h') {
    return 1
  } else if (step_str == 'step_3h') {
    return 1
  } else if (step_str == 'step_6h') {
    return 1
  } else if (step_str == 'step_12h') {
    return 1
  } else if (step_str == 'step_24h') {
    return 1
  } else {
    // 旬 月 季
    return 1
  }
}

//同上，计算右侧label
export function calcMarksRightLabel (step_str, startTime, isTime, i) {
  if (step_str == 'step_1day') {
    let label = isTime ? moment(startTime).add(i * 1, 'days').format('YYYY-MM-DD') : moment(startTime).add(i * 1, 'days').format('YYYY-MM')
    return label
  }
}

//根据模式&间隔&当前时间 计算初始时间
export function getStartTime (tabOption, step_type, now_time) {
  if (tabOption == '历史') {
    if (step_type == 'step_6min') {
      return moment(floorTo6min(now_time)).subtract(12, 'hours').format('YYYY-MM-DD HH:mm:ss')
    }
  }
}
//根据间隔&上一个时间轴的第一个时间，计算向左的下一个时间轴的初始时间
export function getLeftStartTime (step_type, endTime) {
  if (step_type == 'step_6min') {
    return moment(endTime).subtract(200 * 6, 'minutes').format('YYYY-MM-DD HH:mm:ss')
  } else if (step_type == 'step_10min') {
    return moment(endTime).subtract(200 * 10, 'minutes').format('YYYY-MM-DD HH:mm:ss')
  }
}
//同上，计算向右的下一个时间轴的初始时间
export function getRightStartTime (step_type, endTime) {
  if (step_type == 'step_1day') {
    return moment(endTime).add(1, 'days').format('YYYY-MM-DD')
  }
}

//通过间隔 将当前时间计算为已划过的长度
export function calcSatellite_one (step_type) {
  return 120
}

//时间条向左添加刻度
export function addLeftMarks (startKey, tabOption, step_type, endTime) {
  let marksObj = {}
  for (let i = 0; i <= 200; i++) {
    let isFlag = 0;
    let time = '';
    if (step_type == 'step_6min') {
      isFlag = isHourLeft(endTime, (i * calcSteps(step_type)))[0]
      time = isHourLeft(endTime, (i * calcSteps(step_type)))[1]
    } else if (step_type == 'step_10min') {
      isFlag = isHourLeft(endTime, (i * calcSteps(step_type)))[0]
      time = isHourLeft(endTime, (i * calcSteps(step_type)))[1]
    } else if (step_type == 'step_1h') {
      isFlag = isDayLeft(endTime, (i * calcSteps(step_type)))[0]
      time = isDayLeft(endTime, (i * calcSteps(step_type)))[1]
    } else if (step_type == 'step_3h') {
      isFlag = isHourLeft_hours(endTime, (i * calcSteps(step_type)), 3)[0]
      time = isHourLeft_hours(endTime, (i * calcSteps(step_type)), 3)[1]
    } else if (step_type == 'step_6h') {
      isFlag = isHourLeft_hours(endTime, (i * calcSteps(step_type)), 6)[0]
      time = isHourLeft_hours(endTime, (i * calcSteps(step_type)), 6)[1]
    } else if (step_type == 'step_12h') {
      isFlag = isHourLeft_hours(endTime, (i * calcSteps(step_type)), 12)[0]
      time = isHourLeft_hours(endTime, (i * calcSteps(step_type)), 12)[1]
    } else if (step_type == 'step_24h') {
      isFlag = is12Hours_left(endTime, (i * calcSteps(step_type)))[0]
      time = is12Hours_left(endTime, (i * calcSteps(step_type)))[1]
    } else if (step_type == 'step_10days') {
      isFlag = isDayLeft_fivedays(endTime, (i * calcSteps(step_type)), 10)[0]
      time = isDayLeft_fivedays(endTime, (i * calcSteps(step_type)), 10)[1]
    } else if (step_type == 'step_month') {
      isFlag = isDayLeft_fivedays(endTime, (i * calcSteps(step_type)), 5)[0]
      time = isDayLeft_fivedays(endTime, (i * calcSteps(step_type)), 5)[1]
    } else {
      isFlag = isDayLeft_fivedays(endTime, (i * calcSteps(step_type)), 15)[0]
      time = isDayLeft_fivedays(endTime, (i * calcSteps(step_type)), 15)[1]
    }

    marksObj[startKey - i] = {
      key_index: startKey - i,
      style: { color: '#fff' },
      label: isFlag == 1 ? calcMarksLeftLabel(step_type, time) : '',
      time: time,
      step_type: step_type,
      tabOption: '历史'
    }
  }

  return marksObj
}

//判断是否为整点 向左添加刻度专用
export function isHourLeft (timeStr, minutesToSub) {
  let time = moment(timeStr, "YYYY-MM-DD HH:mm");
  let newTime = moment(time).subtract(minutesToSub, 'minutes').format('YYYY-MM-DD HH:mm:ss')
  let result = moment(newTime).format('mm') == '00' ? 1 : 0
  return [result, moment(newTime).format('YYYY-MM-DD HH:mm')]
}

//判断是不是（3，6，12）小时的倍数 向左添加刻度专用
export function isHourLeft_hours (timeStr, hoursToSub, num) {
  let time = moment(timeStr, "YYYY-MM-DD HH:mm");
  let newTime = moment(time).subtract(hoursToSub, 'hours').format('YYYY-MM-DD HH:mm:ss')
  let result = Number(moment(newTime).format('HH')) % num == 0 ? 1 : 0
  return [result, moment(newTime).format('YYYY-MM-DD HH:mm')]
}

//判断是不是（5，10，15）天的倍数 向左添加刻度专用
export function isDayLeft_fivedays (timeStr, daysToSub, num) {
  let time = moment(timeStr, "YYYY-MM-DD");
  let newTime = moment(time).subtract(daysToSub, 'days').format('YYYY-MM-DD');
  let timeNum = Number(moment(newTime).format('DD'));
  let endMonth = Number(moment(newTime).endOf('month').format('DD'));

  let result = 0;
  if (timeNum % num == 0) {
    result = 1
  } else if (timeNum == endMonth && endMonth !== 31) {
    result = 1
  } else {
    result = 0;
  }

  return [result, moment(newTime).format('YYYY-MM-DD')]
}

//判断是否为整天 向左添加刻度专用
export function isDayLeft (timeStr, hoursToSub) {
  let time = moment(timeStr, "YYYY-MM-DD HH:mm");
  let newTime = moment(time).subtract(hoursToSub, 'hours').format('YYYY-MM-DD HH:mm:ss')
  let result = moment(newTime).format('HH') == '00' ? 1 : 0
  return [result, moment(newTime).format('YYYY-MM-DD HH:00')]
}

//判断是否为12:00或24:00 向左添加刻度专用
function is12Hours_left (timeStr, hoursToSub) {
  let time = moment(timeStr, "YYYY-MM-DD HH:mm");
  let newTime = moment(time).subtract(hoursToSub, 'hours').format('YYYY-MM-DD HH:mm:ss')
  let result
  if (moment(newTime).format('HH') == '00') {
    result = 1
  } else if (moment(newTime).format('HH') == '12') {
    result = 1
  } else {
    result = 0
  }
  return [result, moment(newTime).format('YYYY-MM-DD HH:00')]
}

//计算marks中的label或time
export function calcMarksLeftLabel (step_str, time) {
  if (step_str == 'step_6min') {
    return moment(time).format('HH')
  } else if (step_str == 'step_10min') {
    return moment(time).format('HH')
  } else if (step_str == 'step_1h') {
    return moment(time).format('MM-DD')
  } else if (step_str == 'step_3h') {
    return moment(time).format('HH')
  } else if (step_str == 'step_6h') {
    return moment(time).format('HH')
  } else if (step_str == 'step_12h') {
    return moment(time).format('HH')
  } else if (step_str == 'step_24h') {
    return moment(time).format('HH') == '00' ? moment(time).format('MM-DD') : moment(time).format('HH')
  } else if (step_str == 'step_month') {
    return moment(time).format('DD')
  } else {
    return moment(time).format('MM-DD')
  }
}

//时间条向右添加刻度
export function addRightMarks (startKey, tabOption, step_type, startTime) {
  let marksObj = {}
  for (let i = 1; i <= 200; i++) {
    let isFlag = 0;
    let time = '';
    if (step_type == 'step_6min') {
      isFlag = isHourRight(startTime, (i * calcSteps(step_type)))[0]
      time = isHourRight(startTime, (i * calcSteps(step_type)))[1]
    } else if (step_type == 'step_10min') {
      isFlag = isHourRight(startTime, (i * calcSteps(step_type)))[0]
      time = isHourRight(startTime, (i * calcSteps(step_type)))[1]
    } else if (step_type == 'step_1h') {
      isFlag = isDayRight(startTime, (i * calcSteps(step_type)))[0]
      time = isDayRight(startTime, (i * calcSteps(step_type)))[1]
    } else if (step_type == 'step_3h') {
      isFlag = isThreeHours_right(startTime, (i * calcSteps(step_type)), 3)[0]
      time = isThreeHours_right(startTime, (i * calcSteps(step_type)), 3)[1]
    } else if (step_type == 'step_6h') {
      isFlag = isThreeHours_right(startTime, (i * calcSteps(step_type)), 6)[0]
      time = isThreeHours_right(startTime, (i * calcSteps(step_type)), 6)[1]
    } else if (step_type == 'step_12h') {
      isFlag = isThreeHours_right(startTime, (i * calcSteps(step_type)), 12)[0]
      time = isThreeHours_right(startTime, (i * calcSteps(step_type)), 12)[1]
    } else if (step_type == 'step_24h') {
      isFlag = is12Hours_right(startTime, (i * calcSteps(step_type)))[0]
      time = is12Hours_right(startTime, (i * calcSteps(step_type)))[1]
    } else if (step_type == 'step_10days') {
      isFlag = isDayRight_fivedays(startTime, (i * calcSteps(step_type)), 10)[0]
      time = isDayRight_fivedays(startTime, (i * calcSteps(step_type)), 10)[1]
    } else if (step_type == 'step_month') {
      isFlag = isDayRight_fivedays(startTime, (i * calcSteps(step_type)), 5)[0]
      time = isDayRight_fivedays(startTime, (i * calcSteps(step_type)), 5)[1]
    } else {
      isFlag = isDayRight_fivedays(startTime, (i * calcSteps(step_type)), 15)[0]
      time = isDayRight_fivedays(startTime, (i * calcSteps(step_type)), 15)[1]
    }

    marksObj[startKey + i] = {
      key_index: startKey + i,
      style: { color: '#fff' },
      label: isFlag == 1 ? calcMarksLeftLabel(step_type, time) : '',
      time: time,
      step_type: step_type,
      tabOption: tabOption
    }
  }
  return marksObj
}

//判断是否为整点 向右添加刻度专用
function isHourRight (timeStr, minutesToAdd) {
  let time = moment(timeStr, "YYYY-MM-DD HH:mm");
  let newTime = moment(time).add(minutesToAdd, 'minutes').format('YYYY-MM-DD HH:mm:ss')
  let result = moment(newTime).format('mm') == '00' ? 1 : 0
  return [result, moment(newTime).format('YYYY-MM-DD HH:mm')]
}

//判断是否为整天 向右添加刻度专用
function isDayRight (timeStr, hoursToAdd) {
  let time = moment(timeStr, "YYYY-MM-DD HH:mm");
  let newTime = moment(time).add(hoursToAdd, 'hours').format('YYYY-MM-DD HH:mm:ss');
  let result = moment(newTime).format('HH') == '00' ? 1 : 0
  return [result, moment(newTime).format('YYYY-MM-DD HH:00')]
}

//判断是否为12:00或24:00 向右添加刻度专用
function is12Hours_right (timeStr, hoursToAdd) {
  let time = moment(timeStr, "YYYY-MM-DD HH:mm");
  let newTime = moment(time).add(hoursToAdd, 'hours').format('YYYY-MM-DD HH:mm:ss');
  let result
  if (moment(newTime).format('HH') == '00') {
    result = 1
  } else if (moment(newTime).format('HH') == '12') {
    result = 1
  } else {
    result = 0
  }
  return [result, moment(newTime).format('YYYY-MM-DD HH:00')]
}

//判断是否为3h/6h/12h/24h的倍数 向右添加刻度专用
function isThreeHours_right (timeStr, hoursToAdd, num) {
  let time = moment(timeStr, "YYYY-MM-DD HH:mm");
  let newTime = moment(time).add(hoursToAdd, 'hours').format('YYYY-MM-DD HH:mm:ss');
  let hour = Number(moment(newTime).format('HH'))
  let result = hour % num == 0 ? 1 : 0
  return [result, moment(newTime).format('YYYY-MM-DD HH:mm')]
}

//判断是不是（5，10，15）天的倍数 向右添加刻度专用
function isDayRight_fivedays (timeStr, daysToAdd, num) {
  let time = moment(timeStr, "YYYY-MM-DD");
  let newTime = moment(time).add(daysToAdd, 'days').format('YYYY-MM-DD');
  let timeNum = Number(moment(newTime).format('DD'));
  let endMonth = Number(moment(newTime).endOf('month').format('DD'));
  let result = 0;
  if (timeNum % num == 0) {
    result = 1
  } else if (timeNum == endMonth && endMonth !== 31) {
    result = 1
  } else {
    result = 0;
  }

  return [result, moment(newTime).format('YYYY-MM-DD')]
}

//计算初始化label
export function getInitLabel (step_type, startTime, isTime, i) {
  if (step_type == 'step_6min') {
    return isTime ? moment(startTime).add((i * 6), 'minutes').format('YYYY-MM-DD HH:mm') : moment(startTime).add((i * 6), 'minutes').format('HH')
  } else if (step_type == 'step_1h') {
    return isTime ? moment(startTime).add((i * 1), 'hours').format('YYYY-MM-DD HH') : moment(startTime).add((i * 1), 'hours').format('MM-DD')
  } else if (step_type == 'step_month') {
    return isTime ? moment(startTime).add((i * 1), 'day').format('YYYY-MM-DD') : moment(startTime).add((i * 1), 'day').format('YYYY-MM')
  } else if (step_type == 'step_month_ys') {
    return isTime ? moment(startTime).add((i * 1), 'day').format('YYYY-MM-DD') : moment(startTime).add((i * 1), 'day').format('MM-DD')
  }
}

//****初始化****
export function calcMarksInit (step_type, now_time, tabList) {
  let length_one = 120;
  let length_two = 20;
  let length_three = 220;
  let length_four = 72;
  let length_five = 240;
  let length_six = 30;
  let length_seven = 240;

  let markLength = 0

  let marks_one = {} //历史 <0
  let marks_two = {} // 实况 2h
  let marks_three = {} //短临 24h-2h
  let marks_four = {} //短期 3day
  let marks_five = {} //短中期 10day
  let marks_six = {} //延伸期 30day 
  let marks_seven = {} //气候 >30day

  let list = tabList.map(item => {
    return item.name
  })
  let length = list.length - 1

  let marksObj = {} // 创建一个空对象来存储刻度标记的数据
  let nowTime = floorTo6min(now_time)
  let startTime
  if (list[0] == '历史') {
    startTime = moment(nowTime).subtract(12, 'hours').format('YYYY-MM-DD HH:mm:ss')
  } else if (list[0] == '实况') {
    startTime = moment(nowTime).format('YYYY-MM-DD HH:mm:ss')
  } else if (list[0] == '短临') {
    startTime = moment(nowTime).add(6, 'minutes').format('YYYY-MM-DD HH:mm:ss')
  } else if (list[0] == '短期') {
    startTime = moment(nowTime).add(6, 'minutes').add(1, 'days').format('YYYY-MM-DD HH:mm:ss')
  } else if (list[0] == '短中期') {
    startTime = moment(nowTime).add(6, 'minutes').add(4, 'days').format('YYYY-MM-DD HH:mm:ss')
  } else if (list[0] == '延伸期') {
    startTime = moment(nowTime).add(6, 'minutes').add(14, 'days').format('YYYY-MM-DD HH:mm:ss')
  } else if (list[0] == '气候') {
    startTime = moment(nowTime).add(6, 'minutes').add(44, 'days').format('YYYY-MM-DD HH:mm:ss')
  }


  //历史
  if (list.indexOf('历史') >= 0) {
    for (let i = 0; i < 120; i++) {
      let isHourFlag = isHour(startTime, (i * calcSteps(step_type)), true)
      marks_one[markLength + i] = {
        key_index: markLength + i,
        style: { color: '#fff' },
        label: isHourFlag == 1 ? getInitLabel(step_type, startTime, false, i) : '',
        time: getInitLabel(step_type, startTime, true, i),
        step_type: step_type,
        tabOption: '历史'
      }

    }
    markLength = markLength + 120
    startTime = moment(startTime).add((length_one * 6), 'minutes').format('YYYY-MM-DD HH:mm')
  }

  //实况
  if (list.indexOf('实况') >= 0) {
    for (let i = 0; i < 20; i++) {
      let isHourFlag = isHour(startTime, (i * calcSteps(step_type)), true)
      marks_two[markLength + i] = {
        key_index: markLength + i,
        style: { color: '#fff' },
        label: isHourFlag == 1 ? getInitLabel(step_type, startTime, false, i) : '',
        time: getInitLabel(step_type, startTime, true, i),
        step_type: step_type,
        tabOption: i == 0 ? '实况' : '短临'
      }
    }
    markLength = markLength + 20
    startTime = moment(startTime).add((length_two * 6), 'minutes').format('YYYY-MM-DD HH:mm')
  }

  //短临
  if (list.indexOf('短临') >= 0) {
    for (let i = 0; i < 220; i++) {
      let isHourFlag = isHour(startTime, (i * calcSteps(step_type)), true)
      marks_three[markLength + i] = {
        key_index: markLength + i,
        style: { color: '#fff' },
        label: isHourFlag == 1 ? getInitLabel(step_type, startTime, false, i) : '',
        time: getInitLabel(step_type, startTime, true, i),
        step_type: step_type,
        tabOption: '短临'
      }
    }
    markLength = markLength + 220
    startTime = moment(startTime).add((length_three * 6), 'minutes').format('YYYY-MM-DD HH:mm')
  }

  //短期
  if (list.indexOf('短期') >= 0) {
    for (let i = 0; i < 72; i++) {
      let isDayFlag = isDay(startTime, (i * 1))

      marks_four[markLength + i] = {
        key_index: markLength + i,
        style: { color: '#fff' },
        label: isDayFlag == 1 ? getInitLabel('step_1h', startTime, false, i) : '',
        time: getInitLabel('step_1h', startTime, true, i) + ':00',
        step_type: 'step_1h',
        tabOption: '短期'
      }
    }
    markLength = markLength + 72
    startTime = moment(startTime).add((length_four * 1), 'hours').format('YYYY-MM-DD HH') + ':00'
  }

  //短中期
  if (list.indexOf('短中期') >= 0) {
    for (let i = 0; i < 240; i++) {
      let isDayFlag = isDay(startTime, (i * 1))
      marks_five[markLength + i] = {
        key_index: markLength + i,
        style: { color: '#fff' },
        label: isDayFlag == 1 ? getInitLabel('step_1h', startTime, false, i) : '',
        time: getInitLabel('step_1h', startTime, true, i) + ':00',
        step_type: 'step_1h',
        tabOption: '短中期'
      }
    }
    markLength = markLength + 240
    startTime = moment(startTime).add((length_five * 1), 'hours').format('YYYY-MM-DD HH') + ':00'
  }

  //延伸期
  if (list.indexOf('短中期') >= 0) {
    for (let i = 0; i < 30; i++) {
      // let isMonthFlag = isMonth(startTime, (i * 1))
      marks_six[markLength + i] = {
        key_index: markLength + i,
        style: { color: '#fff' },
        // label: isMonthFlag == 1 ? getInitLabel('step_month', startTime, false, i) : '',
        label: i == 14 ? getInitLabel('step_month_ys', startTime, false, i) : '',
        time: getInitLabel('step_month_ys', startTime, true, i),
        step_type: 'step_24h',
        tabOption: '延伸期'
      }
    }
    markLength = 702
    startTime = moment(startTime).add((length_six * 1), 'days').format('YYYY-MM-DD')
  }
  let long_seven = Math.ceil(markLength / 200) * 200;

  //气候
  if (list.indexOf('气候') >= 0) {
    for (let i = 0; i < (long_seven - markLength + 200); i++) {
      let isMonthFlag = isMonth(startTime, (i * 1))
      marks_seven[markLength + i] = {
        key_index: markLength + i,
        style: { color: '#fff' },
        // label: isMonthFlag == 1 ? getInitLabel('step_month', startTime, false, i) : '',
        label: getLabel_fivedays(moment(startTime).add((i * 1), 'days'), 5),
        time: getInitLabel('step_month', startTime, true, i),
        step_type: 'step_month',
        tabOption: '气候'
      }
    }
    markLength = long_seven
    startTime = moment(startTime).add((length_seven * 1), 'days').format('YYYY-MM-DD')
  }

  marksObj = Object.assign({}, marks_one, marks_two, marks_three, marks_four, marks_five, marks_six, marks_seven)
  return [marksObj, markLength]
}

//分割对象 去掉前半部分
function removeObjectKeys (obj, key) {

  // 创建一个新对象来存储剩余的内容
  const newObj = {};

  // 遍历原对象的键
  Object.keys(obj).forEach(k => {
    // 将字符串键转换为数字
    const numericKey = parseInt(k, 10);

    // 如果键大于传入的整数，则保留该属性
    if (numericKey > key) {
      newObj[k] = obj[k];
    }
  });

  return newObj;
}
//分割对象 去掉后半部分
function removeObjectKeys_behind (obj, key) {
  // 创建一个新对象来存储剩余的内容
  const newObj = {};

  // 遍历原对象的键
  Object.keys(obj).forEach(k => {
    // 将字符串键转换为数字
    const numericKey = parseInt(k, 10);

    // 如果键大于传入的整数，则保留该属性
    if (numericKey < key) {
      newObj[k] = obj[k];
    }
  });

  return newObj;
}

//间隔24h时 设置label
function getLabel_24h (time) {
  if (moment(time).format('HH') == '00') {
    return moment(time).format('MM-DD')
  } else if (moment(time).format('HH') == '12') {
    return '12'
  } else {
    return ''
  }
}

//判断是不是5 10 15 天的倍数 如果是月底返回月底（2.28这种情况）
function getLabel_fivedays (time, num) {
  let day = Number(moment(time).format('DD'))
  let endOfMonth = Number(moment(time).endOf('month').format('DD'));

  if (day % num == 0) {
    return num == 5 ? moment(time).format('DD') : moment(time).format('MM-DD')
  } else if (day === endOfMonth && endOfMonth !== 31) {
    return num == 5 ? moment(time).format('DD') : moment(time).format('MM-DD')
  } else {
    return ''
  }
}

//历史-切换间隔
export function changeStep_one (marks, tabOption, step_type, nowTime) {
  let mark_value = Object.values(marks)
  let marks_stage = mark_value.filter((item) => {
    return item.tabOption == tabOption
  })
  let mark_key = marks_stage.map(item => {
    return item.key_index
  })
  let endKey = Math.max.apply(null, mark_key);
  let startKey = Math.min.apply(null, mark_key);

  let endTime = marks[endKey].time
  let result = {}

  let target

  if (step_type == 'step_6min') {
    let minute = moment(endTime).minute()
    let newMinute = Math.floor(minute / 6) * 6
    let newEndTime = moment(endTime).format('YYYY-MM-DD HH') + ':' + (newMinute == '0' ? '00' : newMinute)

    let newStepLong = endKey - startKey; //新时间段长度
    let newMarks = {} //修改间隔后的对象
    for (let i = endKey; i >= startKey; i--) {
      let isHourFlag = isHour(newEndTime, ((newStepLong - i) * 6), false)
      newMarks[i] = {
        key_index: i,
        style: { color: '#fff' },
        label: isHourFlag == 1 ? moment(newEndTime).subtract(((newStepLong - i) * 6), 'minutes').format('HH') : '',
        time: moment(newEndTime).subtract(((newStepLong - i) * 6), 'minutes').format('YYYY-MM-DD HH:mm'),
        step_type: step_type,
        tabOption: '历史'
      }
    }

    let minute_new = moment(nowTime).minute()
    let newMinute_new = Math.floor(minute_new / 6) * 6
    let newNowTime = moment(nowTime).format('YYYY-MM-DD HH') + ':' + (newMinute_new == '0' ? '00' : newMinute_new)
    target = Object.keys(newMarks).filter(item => {
      return newMarks[item].time === newNowTime
    })[0]

    let half_marks = removeObjectKeys(marks, endKey)
    result = Object.assign(newMarks, half_marks)
  } else if (step_type == 'step_10min') {
    let minute = moment(endTime).minute()
    let newMinute = Math.floor(minute / 10) * 10
    let newEndTime = moment(endTime).format('YYYY-MM-DD HH') + ':' + (newMinute == '0' ? '00' : newMinute)

    let newStepLong = endKey - startKey; //新时间段长度
    let newMarks = {} //修改间隔后的对象
    for (let i = endKey; i >= startKey; i--) {
      let isHourFlag = isHour(newEndTime, ((newStepLong - i) * 10), false)
      newMarks[i] = {
        key_index: i,
        style: { color: '#fff' },
        label: isHourFlag == 1 ? moment(newEndTime).subtract(((newStepLong - i) * 10), 'minutes').format('HH') : '',
        time: moment(newEndTime).subtract(((newStepLong - i) * 10), 'minutes').format('YYYY-MM-DD HH:mm'),
        step_type: step_type,
        tabOption: '历史'
      }
    }

    let minute_new = moment(nowTime).minute()
    let newMinute_new = Math.floor(minute_new / 10) * 10
    let newNowTime = moment(nowTime).format('YYYY-MM-DD HH') + ':' + (newMinute_new == '0' ? '00' : newMinute_new)
    target = Object.keys(newMarks).filter(item => {
      return newMarks[item].time === newNowTime
    })[0]

    let half_marks = removeObjectKeys(marks, endKey)
    result = Object.assign(newMarks, half_marks)
  } else if (step_type == 'step_1h') {
    let newEndTime = moment(endTime).format('YYYY-MM-DD HH') + ':00'
    let newStepLong = endKey - startKey; //新时间段长度
    let newMarks = {} //修改间隔后的对象
    for (let i = endKey; i >= startKey; i--) {
      let isFlag = isDay(newEndTime, ((newStepLong - i) * 1), false)
      newMarks[i] = {
        key_index: i,
        style: { color: '#fff' },
        label: isFlag == 1 ? moment(newEndTime).subtract(((newStepLong - i) * 1), 'hours').format('MM-DD') : '',
        time: moment(newEndTime).subtract(((newStepLong - i) * 1), 'hours').format('YYYY-MM-DD HH:00'),
        step_type: step_type,
        tabOption: '历史'
      }
    }

    let hour_new = moment(nowTime).format('YYYY-MM-DD HH:00')
    target = Object.keys(newMarks).filter(item => {
      return newMarks[item].time === hour_new
    })[0]

    let half_marks = removeObjectKeys(marks, endKey)
    result = Object.assign(newMarks, half_marks)

  } else if (step_type == 'step_3h') {
    // let newEndTime = roundDownToNearestThreeHours(endTime, 3) //向下取整3小时倍数
    let newEndTime = moment(endTime).format('YYYY-MM-DD HH') + ':00'
    let newStepLong = endKey - startKey; //新时间段长度
    let newMarks = {} //修改间隔后的对象
    let num = 0
    for (let i = endKey; i >= startKey; i--) {
      num++
      newMarks[i] = {
        key_index: i,
        style: { color: '#fff' },
        label: num % 3 == 0 ? moment(newEndTime).subtract(((newStepLong - i) * 1), 'hours').format('HH') : '',
        time: moment(newEndTime).subtract(((newStepLong - i) * 1), 'hours').format('YYYY-MM-DD HH:00'),
        step_type: step_type,
        tabOption: '历史'
      }
    }

    let hour_new = moment(nowTime).format('YYYY-MM-DD HH:00')
    target = Object.keys(newMarks).filter(item => {
      return newMarks[item].time === hour_new
    })[0]

    let half_marks = removeObjectKeys(marks, endKey)
    result = Object.assign(newMarks, half_marks)

  } else if (step_type == 'step_6h') {
    let newEndTime = moment(endTime).format('YYYY-MM-DD HH') + ':00'
    let newStepLong = endKey - startKey; //新时间段长度
    let newMarks = {} //修改间隔后的对象
    let num = 0
    for (let i = endKey; i >= startKey; i--) {
      num++
      newMarks[i] = {
        key_index: i,
        style: { color: '#fff' },
        label: num % 6 == 0 ? moment(newEndTime).subtract(((newStepLong - i) * 1), 'hours').format('HH') : '',
        time: moment(newEndTime).subtract(((newStepLong - i) * 1), 'hours').format('YYYY-MM-DD HH:00'),
        step_type: step_type,
        tabOption: '历史'
      }
    }
    let hour_new = moment(nowTime).format('YYYY-MM-DD HH:00')
    target = Object.keys(newMarks).filter(item => {
      return newMarks[item].time === hour_new
    })[0]

    let half_marks = removeObjectKeys(marks, endKey)
    result = Object.assign(newMarks, half_marks)
  } else if (step_type == 'step_12h') {
    let newEndTime = moment(endTime).format('YYYY-MM-DD HH') + ':00'
    let newStepLong = endKey - startKey; //新时间段长度
    let newMarks = {} //修改间隔后的对象
    let num = 0

    for (let i = endKey; i >= startKey; i--) {
      num++
      newMarks[i] = {
        key_index: i,
        style: { color: '#fff' },
        label: num % 12 == 0 ? moment(newEndTime).subtract(((newStepLong - i) * 1), 'hours').format('HH') : '',
        time: moment(newEndTime).subtract(((newStepLong - i) * 1), 'hours').format('YYYY-MM-DD HH:00'),
        step_type: step_type,
        tabOption: '历史'
      }
    }
    let hour_new = moment(nowTime).format('YYYY-MM-DD HH:00')
    target = Object.keys(newMarks).filter(item => {
      return newMarks[item].time === hour_new
    })[0]

    let half_marks = removeObjectKeys(marks, endKey)
    result = Object.assign(newMarks, half_marks)
  } else if (step_type == 'step_24h') {
    let newEndTime = moment(endTime).format('YYYY-MM-DD HH') + ':00'
    let newStepLong = endKey - startKey; //新时间段长度
    let newMarks = {} //修改间隔后的对象

    for (let i = endKey; i >= startKey; i--) {
      newMarks[i] = {
        key_index: i,
        style: { color: '#fff' },
        label: getLabel_24h(moment(newEndTime).subtract(((newStepLong - i) * 1), 'hours')),
        time: moment(newEndTime).subtract(((newStepLong - i) * 1), 'hours').format('YYYY-MM-DD HH:00'),
        step_type: step_type,
        tabOption: '历史'
      }
    }

    let hour_new = moment(nowTime).format('YYYY-MM-DD HH:00')
    target = Object.keys(newMarks).filter(item => {
      return newMarks[item].time === hour_new
    })[0]

    let half_marks = removeObjectKeys(marks, endKey)
    result = Object.assign(newMarks, half_marks)
  } else if (step_type == 'step_10days') {
    let newEndTime = moment(endTime).startOf('day').format('YYYY-MM-DD')
    let newStepLong = endKey - startKey; //新时间段长度
    let newMarks = {} //修改间隔后的对象

    for (let i = endKey; i >= startKey; i--) {
      newMarks[i] = {
        key_index: i,
        style: { color: '#fff' },
        label: getLabel_fivedays(moment(newEndTime).subtract(((newStepLong - i) * 1), 'days'), 10),
        time: moment(newEndTime).subtract(((newStepLong - i) * 1), 'days').format('YYYY-MM-DD'),
        step_type: step_type,
        tabOption: '历史'
      }
    }
    let hour_new = moment(nowTime).format('YYYY-MM-DD HH:00')
    target = Object.keys(newMarks).filter(item => {
      return newMarks[item].time === hour_new
    })[0]

    let half_marks = removeObjectKeys(marks, endKey)
    result = Object.assign(newMarks, half_marks)
  } else if (step_type == 'step_month') {
    let newEndTime = moment(endTime).startOf('day').format('YYYY-MM-DD')
    let newStepLong = endKey - startKey; //新时间段长度
    let newMarks = {} //修改间隔后的对象

    for (let i = endKey; i >= startKey; i--) {
      newMarks[i] = {
        key_index: i,
        style: { color: '#fff' },
        label: getLabel_fivedays(moment(newEndTime).subtract(((newStepLong - i) * 1), 'days'), 5),
        time: moment(newEndTime).subtract(((newStepLong - i) * 1), 'days').format('YYYY-MM-DD'),
        step_type: step_type,
        tabOption: '历史'
      }
    }
    let hour_new = moment(nowTime).format('YYYY-MM-DD HH:00')
    target = Object.keys(newMarks).filter(item => {
      return newMarks[item].time === hour_new
    })[0]

    let half_marks = removeObjectKeys(marks, endKey)
    result = Object.assign(newMarks, half_marks)
  } else if (step_type == 'step_season') {
    let newEndTime = moment(endTime).startOf('day').format('YYYY-MM-DD')
    let newStepLong = endKey - startKey; //新时间段长度
    let newMarks = {} //修改间隔后的对象

    for (let i = endKey; i >= startKey; i--) {
      newMarks[i] = {
        key_index: i,
        style: { color: '#fff' },
        label: getLabel_fivedays(moment(newEndTime).subtract(((newStepLong - i) * 1), 'days'), 15),
        time: moment(newEndTime).subtract(((newStepLong - i) * 1), 'days').format('YYYY-MM-DD'),
        step_type: step_type,
        tabOption: '历史'
      }
    }
    let hour_new = moment(nowTime).format('YYYY-MM-DD HH:00')
    target = Object.keys(newMarks).filter(item => {
      return newMarks[item].time === hour_new
    })[0]

    let half_marks = removeObjectKeys(marks, endKey)
    result = Object.assign(newMarks, half_marks)
  }

  return [result, Number(target)]
}

//短临-切换间隔
export function changeStep_three (marks, tabOption, step_type, nowTime) {
  let marks_one = {} //短临之前
  let marks_two = {} //短临
  let marks_three = {} //短临之后

  Object.keys(marks).forEach(key => {
    let value = marks[key];
    if (value.tabOption == '历史' || value.tabOption == '实况') {
      marks_one[key] = value
    } else if (value.tabOption == tabOption) {
      marks_two[key] = value
    } else {
      marks_three[key] = value
    }
  })

  let startKey_two = Number(Object.keys(marks_two)[0])
  let endKey_two = Number(Object.keys(marks_two)[Object.keys(marks_two).length - 1])
  let startTime_two = marks_two[startKey_two].time //起始时间
  let endTime_two = marks_two[endKey_two].time //结束时间
  let newMarks = {}
  let target

  if (step_type == 'step_6min') {
    let minute = moment(startTime_two).minute()
    let newMinute = Math.ceil(minute / 6) * 6
    let newStartTime = moment(startTime_two).format('YYYY-MM-DD HH') + ':' + (newMinute == '0' ? '00' : newMinute)
    let newEndKey = Number(calcStepsCount(newStartTime, endTime_two, 'step_6min')) + Number(startKey_two)

    for (let i = startKey_two; i <= newEndKey; i++) {
      let isFlag = isHour(newStartTime, ((i - startKey_two) * 6), true)
      newMarks[i] = {
        key_index: i,
        style: { color: '#fff' },
        label: isFlag == 1 ? moment(newStartTime).add(((i - startKey_two) * 6), 'minutes').format('HH') : '',
        time: moment(newStartTime).add(((i - startKey_two) * 6), 'minutes').format('YYYY-MM-DD HH:mm'),
        step_type: step_type,
        tabOption: tabOption
      }
    }

    let minute_now = moment(nowTime).minute()
    let minute_now_new = Math.ceil(minute_now / 6) * 6
    let newNowTime = moment(nowTime).format('YYYY-MM-DD HH') + ':' + (minute_now_new == '0' ? '00' : minute_now_new)
    target = Object.keys(newMarks).filter(item => {
      return newMarks[item].time === newNowTime
    })[0]

  } else if (step_type == 'step_10min') {
    let minute = moment(startTime_two).minute()
    let newMinute = Math.ceil(minute / 10) * 10
    let newStartTime = moment(startTime_two).format('YYYY-MM-DD HH') + ':' + (newMinute == '0' ? '00' : newMinute)
    let newEndKey = Number(calcStepsCount(newStartTime, endTime_two, 'step_10min')) + Number(startKey_two)

    for (let i = startKey_two; i <= newEndKey; i++) {
      let isFlag = isHour(newStartTime, ((i - startKey_two) * 10), true)
      newMarks[i] = {
        key_index: i,
        style: { color: '#fff' },
        label: isFlag == 1 ? moment(newStartTime).add(((i - startKey_two) * 10), 'minutes').format('HH') : '',
        time: moment(newStartTime).add(((i - startKey_two) * 10), 'minutes').format('YYYY-MM-DD HH:mm'),
        step_type: step_type,
        tabOption: tabOption
      }
    }

    let minute_now = moment(nowTime).minute()
    let minute_now_new = Math.ceil(minute_now / 10) * 10
    let newNowTime = moment(nowTime).format('YYYY-MM-DD HH') + ':' + (minute_now_new == '0' ? '00' : minute_now_new)
    target = Object.keys(newMarks).filter(item => {
      return newMarks[item].time === newNowTime
    })[0]

  } else if (step_type == 'step_1h') {
    let newStartTime = moment(startTime_two).format('mm') == '00' ? moment(startTime_two).startOf('hours').format('YYYY-MM-DD HH:00') : moment(startTime_two).add(1, 'hours').startOf('hours').format('YYYY-MM-DD HH:00')
    let newEndKey = Number(calcStepsCount(newStartTime, endTime_two, 'step_1h')) + Number(startKey_two)

    for (let i = startKey_two; i <= newEndKey; i++) {
      // let isFlag = isHour(newStartTime, ((i - startKey_two) * 10), true)
      let isFlag = isDay(newStartTime, ((i - startKey_two) * 1), true)
      newMarks[i] = {
        key_index: i,
        style: { color: '#fff' },
        label: isFlag == 1 ? moment(newStartTime).add(((i - startKey_two) * 1), 'hours').format('MM-DD') : '',
        time: moment(newStartTime).add(((i - startKey_two) * 1), 'hours').format('YYYY-MM-DD HH:mm'),
        step_type: step_type,
        tabOption: tabOption
      }
    }

    let newNowTime = moment(nowTime).format('mm') == '00' ? moment(nowTime).startOf('hours').format('YYYY-MM-DD HH:00') : moment(nowTime).add(1, 'hours').startOf('hours').format('YYYY-MM-DD HH:00')
    target = Object.keys(newMarks).filter(item => {
      return newMarks[item].time === newNowTime
    })[0]
  }

  let new_mark_key_two = Object.keys(newMarks)
  let new_endKey_two = Math.max.apply(null, new_mark_key_two); //找到已变更的marks的最后一个key
  let new_marks_three = adjustObjectKeys(marks_three, new_endKey_two + 1) //将第三个marks的key重新排列

  let lastKey_arr = Object.keys(new_marks_three);
  let lastKey = lastKey_arr[lastKey_arr.length - 1];
  let new_lastKey = Math.floor(lastKey / 200) * 200;
  let new_last_marks = removeObjectKeys_behind(new_marks_three, new_lastKey) //去掉气候模块超出200倍数的部分，把问题留给向右无限拉伸的环节

  return [Object.assign(marks_one, newMarks, new_last_marks), Number(target)]
}

//短期-切换间隔
export function changeStep_four (marks, tabOption, step_type, nowTime) {
  let marks_one = {} //短期之前
  let marks_two = {} //短期
  let marks_three = {} //短期之后

  Object.keys(marks).forEach(key => {
    let value = marks[key];
    if (value.tabOption == '历史' || value.tabOption == '实况' || value.tabOption == '短临') {
      marks_one[key] = value
    } else if (value.tabOption == tabOption) {
      marks_two[key] = value
    } else {
      marks_three[key] = value
    }
  })

  let startKey_two = Number(Object.keys(marks_two)[0])
  let endKey_two = Number(Object.keys(marks_two)[Object.keys(marks_two).length - 1])
  let startTime_two = marks_two[startKey_two].time //起始时间
  let endTime_two = marks_two[endKey_two].time //结束时间
  let newMarks = {}
  let target

  if (step_type == 'step_6min') {
    let minute = moment(startTime_two).minute()
    let newMinute = Math.ceil(minute / 6) * 6
    let newStartTime = moment(startTime_two).format('YYYY-MM-DD HH') + ':' + (newMinute == '0' ? '00' : newMinute)
    let newEndKey = Number(calcStepsCount(newStartTime, endTime_two, 'step_6min')) + Number(startKey_two)

    for (let i = startKey_two; i <= newEndKey; i++) {
      let isFlag = isHour(newStartTime, ((i - startKey_two) * 6), true)
      newMarks[i] = {
        key_index: i,
        style: { color: '#fff' },
        label: isFlag == 1 ? moment(newStartTime).add(((i - startKey_two) * 6), 'minutes').format('HH') : '',
        time: moment(newStartTime).add(((i - startKey_two) * 6), 'minutes').format('YYYY-MM-DD HH:mm'),
        step_type: step_type,
        tabOption: tabOption
      }
    }

    let minute_now = moment(nowTime).minute()
    let minute_now_new = Math.ceil(minute_now / 6) * 6
    let newNowTime = moment(nowTime).format('YYYY-MM-DD HH') + ':' + (minute_now_new == '0' ? '00' : minute_now_new)
    target = Object.keys(newMarks).filter(item => {
      return newMarks[item].time === newNowTime
    })[0]

  } else if (step_type == 'step_10min') {
    let minute = moment(startTime_two).minute()
    let newMinute = Math.ceil(minute / 10) * 10
    let newStartTime = moment(startTime_two).format('YYYY-MM-DD HH') + ':' + (newMinute == '0' ? '00' : newMinute)
    let newEndKey = Number(calcStepsCount(newStartTime, endTime_two, 'step_10min')) + Number(startKey_two)

    for (let i = startKey_two; i <= newEndKey; i++) {
      let isFlag = isHour(newStartTime, ((i - startKey_two) * 10), true)
      newMarks[i] = {
        key_index: i,
        style: { color: '#fff' },
        label: isFlag == 1 ? moment(newStartTime).add(((i - startKey_two) * 10), 'minutes').format('HH') : '',
        time: moment(newStartTime).add(((i - startKey_two) * 10), 'minutes').format('YYYY-MM-DD HH:mm'),
        step_type: step_type,
        tabOption: tabOption
      }
    }

    let minute_now = moment(nowTime).minute()
    let minute_now_new = Math.ceil(minute_now / 10) * 10
    let newNowTime = moment(nowTime).format('YYYY-MM-DD HH') + ':' + (minute_now_new == '0' ? '00' : minute_now_new)
    target = Object.keys(newMarks).filter(item => {
      return newMarks[item].time === newNowTime
    })[0]

  } else if (step_type == 'step_1h') {
    let newStartTime = moment(startTime_two).format('mm') == '00' ? moment(startTime_two).startOf('hours').format('YYYY-MM-DD HH:00') : moment(startTime_two).add(1, 'hours').startOf('hours').format('YYYY-MM-DD HH:00')
    let newEndKey = Number(calcStepsCount(newStartTime, endTime_two, 'step_1h')) + Number(startKey_two)

    for (let i = startKey_two; i <= newEndKey; i++) {
      let isFlag = isDay(newStartTime, ((i - startKey_two) * 1), true)
      newMarks[i] = {
        key_index: i,
        style: { color: '#fff' },
        label: isFlag == 1 ? moment(newStartTime).add(((i - startKey_two) * 1), 'hours').format('MM-DD') : '',
        time: moment(newStartTime).add(((i - startKey_two) * 1), 'hours').format('YYYY-MM-DD HH:mm'),
        step_type: step_type,
        tabOption: tabOption
      }
    }

    let newNowTime = moment(nowTime).format('mm') == '00' ? moment(nowTime).startOf('hours').format('YYYY-MM-DD HH:00') : moment(nowTime).add(1, 'hours').startOf('hours').format('YYYY-MM-DD HH:00')
    target = Object.keys(newMarks).filter(item => {
      return newMarks[item].time === newNowTime
    })[0]
  } else if (step_type == 'step_3h') {
    let hour = moment(startTime_two).hour()
    let newhour = Math.ceil(hour / 3) * 3
    let newStartTime = moment(startTime_two).format('YYYY-MM-DD ') + (newhour == '0' ? '00' : newhour) + ':00'
    let newEndKey = Number(calcStepsCount(newStartTime, endTime_two, 'step_3h')) + Number(startKey_two)

    for (let i = startKey_two; i <= newEndKey; i++) {
      let isFlag = isDay(newStartTime, ((i - startKey_two) * 3), true)
      newMarks[i] = {
        key_index: i,
        style: { color: '#fff' },
        label: isFlag == 1 ? moment(newStartTime).add(((i - startKey_two) * 3), 'hours').format('MM-DD') : '',
        time: moment(newStartTime).add(((i - startKey_two) * 3), 'hours').format('YYYY-MM-DD HH:mm'),
        step_type: step_type,
        tabOption: tabOption
      }
    }

    let hour_now = moment(nowTime).hour()
    let hour_now_new = Math.ceil(hour_now / 3) * 3
    let newNowTime = moment(nowTime).format('YYYY-MM-DD ') + (hour_now_new == '0' ? '00' : hour_now_new) + ':00'
    target = Object.keys(newMarks).filter(item => {
      return newMarks[item].time === newNowTime
    })[0]
  } else if (step_type == 'step_6h') {
    let newStartTime = moment(startTime_two).format('HH') == '00' ? moment(startTime_two).startOf('hours').format('YYYY-MM-DD HH:00') : moment(startTime_two).add(1, 'hours').startOf('hours').format('YYYY-MM-DD HH:00')
    let newEndKey = Number(calcStepsCount(newStartTime, endTime_two, 'step_1h')) + Number(startKey_two)
    for (let i = startKey_two; i <= newEndKey; i++) {
      let isFlag = isThreeHours(newStartTime, ((i - startKey_two) * 1), 6)
      newMarks[i] = {
        key_index: i,
        style: { color: '#fff' },
        label: isFlag == 1 ? moment(newStartTime).add(((i - startKey_two) * 1), 'hours').format('HH') : '',
        time: moment(newStartTime).add(((i - startKey_two) * 1), 'hours').format('YYYY-MM-DD HH:mm'),
        step_type: step_type,
        tabOption: tabOption
      }
    }
    let newNowTime = moment(nowTime).add(1, 'hours').startOf('hours').format('YYYY-MM-DD HH:00')
    target = Object.keys(newMarks).filter(item => {
      return newMarks[item].time === newNowTime
    })[0]
  } else if (step_type == 'step_12h') {
    let newStartTime = moment(startTime_two).format('HH') == '00' ? moment(startTime_two).startOf('hours').format('YYYY-MM-DD HH:00') : moment(startTime_two).add(1, 'hours').startOf('hours').format('YYYY-MM-DD HH:00')
    let newEndKey = Number(calcStepsCount(newStartTime, endTime_two, 'step_1h')) + Number(startKey_two)
    for (let i = startKey_two; i <= newEndKey; i++) {
      let isFlag = isThreeHours(newStartTime, ((i - startKey_two) * 1), 12)
      newMarks[i] = {
        key_index: i,
        style: { color: '#fff' },
        label: isFlag == 1 ? moment(newStartTime).add(((i - startKey_two) * 1), 'hours').format('HH') : '',
        time: moment(newStartTime).add(((i - startKey_two) * 1), 'hours').format('YYYY-MM-DD HH:mm'),
        step_type: step_type,
        tabOption: tabOption
      }
    }
    let newNowTime = moment(nowTime).add(1, 'hours').startOf('hours').format('YYYY-MM-DD HH:00')
    target = Object.keys(newMarks).filter(item => {
      return newMarks[item].time === newNowTime
    })[0]
  }

  let new_mark_key_two = Object.keys(newMarks)
  let new_endKey_two = Math.max.apply(null, new_mark_key_two); //找到已变更的marks的最后一个key
  let new_marks_three = adjustObjectKeys(marks_three, new_endKey_two + 1) //将第三个marks的key重新排列

  let lastKey_arr = Object.keys(new_marks_three);
  let lastKey = lastKey_arr[lastKey_arr.length - 1];
  let new_lastKey = Math.floor(lastKey / 200) * 200;
  let new_last_marks = removeObjectKeys_behind(new_marks_three, new_lastKey) //去掉气候模块超出200倍数的部分，把问题留给向右无限拉伸的环节

  return [Object.assign(marks_one, newMarks, new_last_marks), Number(target)]
}

//短中期-切换间隔
export function changeStep_five (marks, tabOption, step_type, nowTime) {
  let marks_one = {} //短中期之前
  let marks_two = {} //短中期
  let marks_three = {} //短中期之后

  Object.keys(marks).forEach(key => {
    let value = marks[key];
    if (value.tabOption == '历史' || value.tabOption == '实况' || value.tabOption == '短临' || value.tabOption == '短期') {
      marks_one[key] = value
    } else if (value.tabOption == tabOption) {
      marks_two[key] = value
    } else {
      marks_three[key] = value
    }
  })

  let startKey_two = Number(Object.keys(marks_two)[0])
  let endKey_two = Number(Object.keys(marks_two)[Object.keys(marks_two).length - 1])
  let startTime_two = marks_two[startKey_two].time //起始时间
  let endTime_two = marks_two[endKey_two].time //结束时间
  let newMarks = {}
  let target

  if (step_type == 'step_6min') {
    let minute = moment(startTime_two).minute()
    let newMinute = Math.ceil(minute / 6) * 6
    let newStartTime = moment(startTime_two).format('YYYY-MM-DD HH') + ':' + (newMinute == '0' ? '00' : newMinute)
    let newEndKey = Number(calcStepsCount(newStartTime, endTime_two, 'step_6min')) + Number(startKey_two)

    for (let i = startKey_two; i <= newEndKey; i++) {
      let isFlag = isHour(newStartTime, ((i - startKey_two) * 6), true)
      newMarks[i] = {
        key_index: i,
        style: { color: '#fff' },
        label: isFlag == 1 ? moment(newStartTime).add(((i - startKey_two) * 6), 'minutes').format('HH') : '',
        time: moment(newStartTime).add(((i - startKey_two) * 6), 'minutes').format('YYYY-MM-DD HH:mm'),
        step_type: step_type,
        tabOption: tabOption
      }
    }

    let minute_now = moment(nowTime).minute()
    let minute_now_new = Math.ceil(minute_now / 6) * 6
    let newNowTime = moment(nowTime).format('YYYY-MM-DD HH') + ':' + (minute_now_new == '0' ? '00' : minute_now_new)
    target = Object.keys(newMarks).filter(item => {
      return newMarks[item].time === newNowTime
    })[0]

  } else if (step_type == 'step_10min') {
    let minute = moment(startTime_two).minute()
    let newMinute = Math.ceil(minute / 10) * 10
    let newStartTime = moment(startTime_two).format('YYYY-MM-DD HH') + ':' + (newMinute == '0' ? '00' : newMinute)
    let newEndKey = Number(calcStepsCount(newStartTime, endTime_two, 'step_10min')) + Number(startKey_two)

    for (let i = startKey_two; i <= newEndKey; i++) {
      let isFlag = isHour(newStartTime, ((i - startKey_two) * 10), true)
      newMarks[i] = {
        key_index: i,
        style: { color: '#fff' },
        label: isFlag == 1 ? moment(newStartTime).add(((i - startKey_two) * 10), 'minutes').format('HH') : '',
        time: moment(newStartTime).add(((i - startKey_two) * 10), 'minutes').format('YYYY-MM-DD HH:mm'),
        step_type: step_type,
        tabOption: tabOption
      }
    }

    let minute_now = moment(nowTime).minute()
    let minute_now_new = Math.ceil(minute_now / 10) * 10
    let newNowTime = moment(nowTime).format('YYYY-MM-DD HH') + ':' + (minute_now_new == '0' ? '00' : minute_now_new)
    target = Object.keys(newMarks).filter(item => {
      return newMarks[item].time === newNowTime
    })[0]

  } else if (step_type == 'step_1h') {
    let newStartTime = moment(startTime_two).format('mm') == '00' ? moment(startTime_two).startOf('hours').format('YYYY-MM-DD HH:00') : moment(startTime_two).add(1, 'hours').startOf('hours').format('YYYY-MM-DD HH:00')
    let newEndKey = Number(calcStepsCount(newStartTime, endTime_two, 'step_1h')) + Number(startKey_two)

    for (let i = startKey_two; i <= newEndKey; i++) {
      let isFlag = isDay(newStartTime, ((i - startKey_two) * 1), true)
      newMarks[i] = {
        key_index: i,
        style: { color: '#fff' },
        label: isFlag == 1 ? moment(newStartTime).add(((i - startKey_two) * 1), 'hours').format('MM-DD') : '',
        time: moment(newStartTime).add(((i - startKey_two) * 1), 'hours').format('YYYY-MM-DD HH:mm'),
        step_type: step_type,
        tabOption: tabOption
      }
    }

    let newNowTime = moment(nowTime).format('mm') == '00' ? moment(nowTime).startOf('hours').format('YYYY-MM-DD HH:00') : moment(nowTime).add(1, 'hours').startOf('hours').format('YYYY-MM-DD HH:00')
    target = Object.keys(newMarks).filter(item => {
      return newMarks[item].time === newNowTime
    })[0]
  } else if (step_type == 'step_3h') {
    let hour = moment(startTime_two).hour()
    let newhour = Math.ceil(hour / 3) * 3
    let newStartTime = moment(startTime_two).format('YYYY-MM-DD ') + (newhour == '0' ? '00' : newhour) + ':00'
    let newEndKey = Number(calcStepsCount(newStartTime, endTime_two, 'step_3h')) + Number(startKey_two)

    for (let i = startKey_two; i <= newEndKey; i++) {
      let isFlag = isDay(newStartTime, ((i - startKey_two) * 3), true)
      newMarks[i] = {
        key_index: i,
        style: { color: '#fff' },
        label: isFlag == 1 ? moment(newStartTime).add(((i - startKey_two) * 3), 'hours').format('MM-DD') : '',
        time: moment(newStartTime).add(((i - startKey_two) * 3), 'hours').format('YYYY-MM-DD HH:mm'),
        step_type: step_type,
        tabOption: tabOption
      }
    }

    let hour_now = moment(nowTime).hour()
    let hour_now_new = Math.ceil(hour_now / 3) * 3
    let newNowTime = moment(nowTime).format('YYYY-MM-DD ') + (hour_now_new == '0' ? '00' : hour_now_new) + ':00'
    target = Object.keys(newMarks).filter(item => {
      return newMarks[item].time === newNowTime
    })[0]
  } else if (step_type == 'step_6h') {
    let newStartTime = moment(startTime_two).format('mm') == '00' ? moment(startTime_two).startOf('hours').format('YYYY-MM-DD HH:00') : moment(startTime_two).add(1, 'hours').startOf('hours').format('YYYY-MM-DD HH:00')
    let newEndKey = Number(calcStepsCount(newStartTime, endTime_two, 'step_1h')) + Number(startKey_two)
    for (let i = startKey_two; i <= newEndKey; i++) {
      let isFlag = isThreeHours(newStartTime, ((i - startKey_two) * 1), 6)
      newMarks[i] = {
        key_index: i,
        style: { color: '#fff' },
        label: isFlag == 1 ? moment(newStartTime).add(((i - startKey_two) * 1), 'hours').format('HH') : '',
        time: moment(newStartTime).add(((i - startKey_two) * 1), 'hours').format('YYYY-MM-DD HH:mm'),
        step_type: step_type,
        tabOption: tabOption
      }
    }
    let newNowTime = moment(nowTime).format('mm') == '00' ? moment(nowTime).startOf('hours').format('YYYY-MM-DD HH:00') : moment(nowTime).add(1, 'hours').startOf('hours').format('YYYY-MM-DD HH:00')
    target = Object.keys(newMarks).filter(item => {
      return newMarks[item].time === newNowTime
    })[0]
  } else if (step_type == 'step_12h') {
    let newStartTime = moment(startTime_two).format('HH') == '00' ? moment(startTime_two).startOf('hours').format('YYYY-MM-DD HH:00') : moment(startTime_two).add(1, 'hours').startOf('hours').format('YYYY-MM-DD HH:00')
    let newEndKey = Number(calcStepsCount(newStartTime, endTime_two, 'step_1h')) + Number(startKey_two)
    for (let i = startKey_two; i <= newEndKey; i++) {
      let isFlag = isThreeHours(newStartTime, ((i - startKey_two) * 1), 12)
      newMarks[i] = {
        key_index: i,
        style: { color: '#fff' },
        label: isFlag == 1 ? moment(newStartTime).add(((i - startKey_two) * 1), 'hours').format('HH') : '',
        time: moment(newStartTime).add(((i - startKey_two) * 1), 'hours').format('YYYY-MM-DD HH:mm'),
        step_type: step_type,
        tabOption: tabOption
      }
    }
    let newNowTime = moment(nowTime).add(1, 'hours').startOf('hours').format('YYYY-MM-DD HH:00')
    target = Object.keys(newMarks).filter(item => {
      return newMarks[item].time === newNowTime
    })[0]
  } else if (step_type == 'step_24h') {
    let newStartTime = moment(startTime_two).format('mm') == '00' ? moment(startTime_two).startOf('hours').format('YYYY-MM-DD HH:00') : moment(startTime_two).add(1, 'hours').startOf('hours').format('YYYY-MM-DD HH:00')
    let newEndKey = Number(calcStepsCount(newStartTime, endTime_two, 'step_1h')) + Number(startKey_two)

    for (let i = startKey_two; i <= newEndKey; i++) {
      let isFlag = isDay(newStartTime, ((i - startKey_two) * 1), true)
      newMarks[i] = {
        key_index: i,
        style: { color: '#fff' },
        label: isFlag == 1 ? moment(newStartTime).add(((i - startKey_two) * 1), 'hours').format('MM-DD') : '',
        time: moment(newStartTime).add(((i - startKey_two) * 1), 'hours').format('YYYY-MM-DD HH:mm'),
        step_type: step_type,
        tabOption: tabOption
      }
    }

    let newNowTime = moment(nowTime).format('mm') == '00' ? moment(nowTime).startOf('hours').format('YYYY-MM-DD HH:00') : moment(nowTime).add(1, 'hours').startOf('hours').format('YYYY-MM-DD HH:00')
    target = Object.keys(newMarks).filter(item => {
      return newMarks[item].time === newNowTime
    })[0]
  }

  let new_mark_key_two = Object.keys(newMarks)
  let new_endKey_two = Math.max.apply(null, new_mark_key_two); //找到已变更的marks的最后一个key
  let new_marks_three = adjustObjectKeys(marks_three, new_endKey_two + 1) //将第三个marks的key重新排列

  let lastKey_arr = Object.keys(new_marks_three);
  let lastKey = lastKey_arr[lastKey_arr.length - 1];
  let new_lastKey = Math.floor(lastKey / 200) * 200;
  let new_last_marks = removeObjectKeys_behind(new_marks_three, new_lastKey) //去掉气候模块超出200倍数的部分，把问题留给向右无限拉伸的环节

  return [Object.assign(marks_one, newMarks, new_last_marks), Number(target)]
}

//延伸期-切换间隔
export function changeStep_six (marks, tabOption, step_type, nowTime) {
  let marks_one = {} //延伸期之前
  let marks_two = {} //延伸期
  let marks_three = {} //延伸期之后

  Object.keys(marks).forEach(key => {
    let value = marks[key];
    if (value.tabOption == '历史' || value.tabOption == '实况' || value.tabOption == '短临' || value.tabOption == '短期' || value.tabOption == '短中期') {
      marks_one[key] = value
    } else if (value.tabOption == tabOption) {
      marks_two[key] = value
    } else {
      marks_three[key] = value
    }
  })

  let startKey_two = Number(Object.keys(marks_two)[0])
  let endKey_two = Number(Object.keys(marks_two)[Object.keys(marks_two).length - 1])
  let startTime_two = marks_two[startKey_two].time //起始时间
  let endTime_two = marks_two[endKey_two].time //结束时间
  let newMarks = {}
  let target

  if (step_type == 'step_6min') {
    let minute = moment(startTime_two).minute()
    let newMinute = Math.ceil(minute / 6) * 6
    let newStartTime = moment(startTime_two).format('YYYY-MM-DD HH') + ':' + (newMinute == '0' ? '00' : newMinute)
    let newEndKey = Number(calcStepsCount(newStartTime, endTime_two, 'step_6min')) + Number(startKey_two)

    for (let i = startKey_two; i <= newEndKey; i++) {
      let isFlag = isHour(newStartTime, ((i - startKey_two) * 6), true)
      newMarks[i] = {
        key_index: i,
        style: { color: '#fff' },
        label: isFlag == 1 ? moment(newStartTime).add(((i - startKey_two) * 6), 'minutes').format('HH') : '',
        time: moment(newStartTime).add(((i - startKey_two) * 6), 'minutes').format('YYYY-MM-DD HH:mm'),
        step_type: step_type,
        tabOption: tabOption
      }
    }

    let minute_now = moment(nowTime).minute()
    let minute_now_new = Math.ceil(minute_now / 6) * 6
    let newNowTime = moment(nowTime).format('YYYY-MM-DD HH') + ':' + (minute_now_new == '0' ? '00' : minute_now_new)
    target = Object.keys(newMarks).filter(item => {
      return newMarks[item].time === newNowTime
    })[0]

  } else if (step_type == 'step_10min') {
    let minute = moment(startTime_two).minute()
    let newMinute = Math.ceil(minute / 10) * 10
    let newStartTime = moment(startTime_two).format('YYYY-MM-DD HH') + ':' + (newMinute == '0' ? '00' : newMinute)
    let newEndKey = Number(calcStepsCount(newStartTime, endTime_two, 'step_10min')) + Number(startKey_two)

    for (let i = startKey_two; i <= newEndKey; i++) {
      let isFlag = isHour(newStartTime, ((i - startKey_two) * 10), true)
      newMarks[i] = {
        key_index: i,
        style: { color: '#fff' },
        label: isFlag == 1 ? moment(newStartTime).add(((i - startKey_two) * 10), 'minutes').format('HH') : '',
        time: moment(newStartTime).add(((i - startKey_two) * 10), 'minutes').format('YYYY-MM-DD HH:mm'),
        step_type: step_type,
        tabOption: tabOption
      }
    }

    let minute_now = moment(nowTime).minute()
    let minute_now_new = Math.ceil(minute_now / 10) * 10
    let newNowTime = moment(nowTime).format('YYYY-MM-DD HH') + ':' + (minute_now_new == '0' ? '00' : minute_now_new)
    target = Object.keys(newMarks).filter(item => {
      return newMarks[item].time === newNowTime
    })[0]

  } else if (step_type == 'step_1h') {
    let newStartTime = moment(startTime_two).format('mm') == '00' ? moment(startTime_two).startOf('hours').format('YYYY-MM-DD HH:00') : moment(startTime_two).add(1, 'hours').startOf('hours').format('YYYY-MM-DD HH:00')
    let newEndKey = Number(calcStepsCount(newStartTime, endTime_two, 'step_1h')) + Number(startKey_two)

    for (let i = startKey_two; i <= newEndKey; i++) {
      let isFlag = isDay(newStartTime, ((i - startKey_two) * 1), true)
      newMarks[i] = {
        key_index: i,
        style: { color: '#fff' },
        label: isFlag == 1 ? moment(newStartTime).add(((i - startKey_two) * 1), 'hours').format('MM-DD') : '',
        time: moment(newStartTime).add(((i - startKey_two) * 1), 'hours').format('YYYY-MM-DD HH:mm'),
        step_type: step_type,
        tabOption: tabOption
      }
    }

    let newNowTime = moment(nowTime).format('mm') == '00' ? moment(nowTime).startOf('hours').format('YYYY-MM-DD HH:00') : moment(nowTime).add(1, 'hours').startOf('hours').format('YYYY-MM-DD HH:00')
    target = Object.keys(newMarks).filter(item => {
      return newMarks[item].time === newNowTime
    })[0]
  } else if (step_type == 'step_3h') {
    let hour = moment(startTime_two).hour()
    let newhour = Math.ceil(hour / 3) * 3
    let newStartTime = moment(startTime_two).format('YYYY-MM-DD ') + (newhour == '0' ? '00' : newhour) + ':00'
    let newEndKey = Number(calcStepsCount(newStartTime, endTime_two, 'step_3h')) + Number(startKey_two)

    for (let i = startKey_two; i <= newEndKey; i++) {
      let isFlag = isDay(newStartTime, ((i - startKey_two) * 3), true)
      newMarks[i] = {
        key_index: i,
        style: { color: '#fff' },
        label: isFlag == 1 ? moment(newStartTime).add(((i - startKey_two) * 3), 'hours').format('MM-DD') : '',
        time: moment(newStartTime).add(((i - startKey_two) * 3), 'hours').format('YYYY-MM-DD HH:mm'),
        step_type: step_type,
        tabOption: tabOption
      }
    }

    let hour_now = moment(nowTime).hour()
    let hour_now_new = Math.ceil(hour_now / 3) * 3
    let newNowTime = moment(nowTime).format('YYYY-MM-DD ') + (hour_now_new == '0' ? '00' : hour_now_new) + ':00'
    target = Object.keys(newMarks).filter(item => {
      return newMarks[item].time === newNowTime
    })[0]
  } else if (step_type == 'step_6h') {
    let newStartTime = moment(startTime_two).format('HH') == '00' ? moment(startTime_two).startOf('hours').format('YYYY-MM-DD HH:00') : moment(startTime_two).add(1, 'hours').startOf('hours').format('YYYY-MM-DD HH:00')
    let newEndKey = Number(calcStepsCount(newStartTime, endTime_two, 'step_1h')) + Number(startKey_two)
    for (let i = startKey_two; i <= newEndKey; i++) {
      let isFlag = isThreeHours(newStartTime, ((i - startKey_two) * 1), 6)
      newMarks[i] = {
        key_index: i,
        style: { color: '#fff' },
        label: isFlag == 1 ? moment(newStartTime).add(((i - startKey_two) * 1), 'hours').format('HH') : '',
        time: moment(newStartTime).add(((i - startKey_two) * 1), 'hours').format('YYYY-MM-DD HH:mm'),
        step_type: step_type,
        tabOption: tabOption
      }
    }
    let newNowTime = moment(nowTime).add(1, 'hours').startOf('hours').format('YYYY-MM-DD HH:00')
    target = Object.keys(newMarks).filter(item => {
      return newMarks[item].time === newNowTime
    })[0]
  } else if (step_type == 'step_12h') {
    let newStartTime = moment(startTime_two).format('HH') == '00' ? moment(startTime_two).startOf('hours').format('YYYY-MM-DD HH:00') : moment(startTime_two).add(1, 'hours').startOf('hours').format('YYYY-MM-DD HH:00')
    let newEndKey = Number(calcStepsCount(newStartTime, endTime_two, 'step_1h')) + Number(startKey_two)
    for (let i = startKey_two; i <= newEndKey; i++) {
      let isFlag = isThreeHours(newStartTime, ((i - startKey_two) * 1), 12)
      newMarks[i] = {
        key_index: i,
        style: { color: '#fff' },
        label: isFlag == 1 ? moment(newStartTime).add(((i - startKey_two) * 1), 'hours').format('HH') : '',
        time: moment(newStartTime).add(((i - startKey_two) * 1), 'hours').format('YYYY-MM-DD HH:mm'),
        step_type: step_type,
        tabOption: tabOption
      }
    }
    let newNowTime = moment(nowTime).add(1, 'hours').startOf('hours').format('YYYY-MM-DD HH:00')
    target = Object.keys(newMarks).filter(item => {
      return newMarks[item].time === newNowTime
    })[0]
  } else if (step_type == 'step_24h') {
    let newStartTime = moment(startTime_two).format('HH') == '00' ? moment(startTime_two).startOf('days').format('YYYY-MM-DD') : moment(startTime_two).add(1, 'days').startOf('days').format('YYYY-MM-DD')
    let newEndKey = Number(calcStepsCount(newStartTime, endTime_two, 'step_24h')) + Number(startKey_two)
    for (let i = startKey_two; i <= newEndKey; i++) {
      newMarks[i] = {
        key_index: i,
        style: { color: '#fff' },
        // label: isFlag == 1 ? moment(newStartTime).add(((i - startKey_two) * 1), 'hours').format('HH') : '',
        // time: moment(newStartTime).add(((i - startKey_two) * 1), 'hours').format('YYYY-MM-DD HH:mm'),
        label: i == getMiddleInteger(startKey_two, newEndKey) ? getInitLabel('step_month_ys', newStartTime, false, (i - startKey_two)) : '',
        time: getInitLabel('step_month_ys', newStartTime, true, (i - startKey_two)),
        step_type: step_type,
        tabOption: tabOption
      }
    }
    let newNowTime = moment(nowTime).format('HH') == '00' ? moment(nowTime).startOf('days').format('YYYY-MM-DD') : moment(nowTime).add(1, 'days').startOf('days').format('YYYY-MM-DD')
    target = Object.keys(newMarks).filter(item => {
      return newMarks[item].time === newNowTime
    })[0]
  }

  let new_mark_key_two = Object.keys(newMarks)
  let new_endKey_two = Math.max.apply(null, new_mark_key_two); //找到已变更的marks的最后一个key
  let new_marks_three = adjustObjectKeys(marks_three, new_endKey_two + 1) //将第三个marks的key重新排列

  let lastKey_arr = Object.keys(new_marks_three);
  let lastKey = lastKey_arr[lastKey_arr.length - 1];
  let new_lastKey = Math.floor(lastKey / 200) * 200;
  let new_last_marks = removeObjectKeys_behind(new_marks_three, new_lastKey) //去掉气候模块超出200倍数的部分，把问题留给向右无限拉伸的环节

  return [Object.assign(marks_one, newMarks, new_last_marks), Number(target)]
}

//气候-切换间隔
export function changeStep_seven (marks, tabOption, step_type, nowTime) {
  let mark_value = Object.values(marks)
  let marks_stage = mark_value.filter((item) => {
    return item.tabOption == tabOption
  })
  let mark_key = marks_stage.map(item => {
    return item.key_index
  })
  let endKey = Math.max.apply(null, mark_key);
  let startKey = Math.min.apply(null, mark_key);

  let startTime = marks[startKey].time
  let result = {}
  let target

  if (step_type == 'step_6min') {
    let minute = moment(startTime).minute()
    let newMinute = Math.floor(minute / 6) * 6
    let newStartTime = moment(startTime).format('YYYY-MM-DD HH') + ':' + (newMinute == '0' ? '00' : newMinute)

    let newMarks = {} //修改间隔后的对象

    for (let i = startKey; i <= endKey; i++) {
      let isHourFlag = isHour(newStartTime, ((i - startKey) * 6), true)
      newMarks[i] = {
        key_index: i,
        style: { color: '#fff' },
        label: isHourFlag == 1 ? moment(newStartTime).add(((i - startKey) * 6), 'minutes').format('HH') : '',
        time: moment(newStartTime).add(((i - startKey) * 6), 'minutes').format('YYYY-MM-DD HH:mm'),
        step_type: step_type,
        tabOption: '气候'
      }
    }
    let minute_new = moment(nowTime).minute()
    let newMinute_new = Math.ceil(minute_new / 6) * 6
    let newNowTime = moment(nowTime).format('YYYY-MM-DD HH') + ':' + (newMinute_new == '0' ? '00' : newMinute_new)
    target = Object.keys(newMarks).filter(item => {
      return newMarks[item].time === newNowTime
    })[0]

    let half_marks = removeObjectKeys_behind(marks, startKey)
    result = Object.assign(half_marks, newMarks)
  } else if (step_type == 'step_10min') {
    let minute = moment(startTime).minute()
    let newMinute = Math.floor(minute / 10) * 10
    let newStartTime = moment(startTime).format('YYYY-MM-DD HH') + ':' + (newMinute == '0' ? '00' : newMinute)

    let newMarks = {} //修改间隔后的对象

    for (let i = startKey; i <= endKey; i++) {
      let isHourFlag = isHour(newStartTime, ((i - startKey) * 10), true)
      newMarks[i] = {
        key_index: i,
        style: { color: '#fff' },
        label: isHourFlag == 1 ? moment(newStartTime).add(((i - startKey) * 10), 'minutes').format('HH') : '',
        time: moment(newStartTime).add(((i - startKey) * 10), 'minutes').format('YYYY-MM-DD HH:mm'),
        step_type: step_type,
        tabOption: '气候'
      }
    }
    let minute_new = moment(nowTime).minute()
    let newMinute_new = Math.ceil(minute_new / 10) * 10
    let newNowTime = moment(nowTime).format('YYYY-MM-DD HH') + ':' + (newMinute_new == '0' ? '00' : newMinute_new)
    target = Object.keys(newMarks).filter(item => {
      return newMarks[item].time === newNowTime
    })[0]

    let half_marks = removeObjectKeys_behind(marks, startKey)
    result = Object.assign(half_marks, newMarks)
  } else if (step_type == 'step_1h') {
    let newStartTime = moment(startTime).format('mm') == '00' ? moment(startTime).format('YYYY-MM-DD HH:00') : moment(startTime).add(1, 'hours').startOf('hours').format('YYYY-MM-DD HH:00')

    let newMarks = {} //修改间隔后的对象
    for (let i = startKey; i <= endKey; i++) {
      let isDayFlag = isDay(newStartTime, (i - startKey), true)
      newMarks[i] = {
        key_index: i,
        style: { color: '#fff' },
        label: isDayFlag == 1 ? moment(newStartTime).add(((i - startKey) * 1), 'hours').format('MM-DD') : '',
        time: moment(newStartTime).add(((i - startKey) * 1), 'hours').format('YYYY-MM-DD HH:00'),
        step_type: step_type,
        tabOption: '气候'
      }
    }
    let newNowTime = moment(nowTime).format('mm') == '00' ? moment(nowTime).startOf('hours').format('YYYY-MM-DD HH:00') : moment(nowTime).add(1, 'hours').startOf('hours').format('YYYY-MM-DD HH:00')
    target = Object.keys(newMarks).filter(item => {
      return newMarks[item].time === newNowTime
    })[0]

    let half_marks = removeObjectKeys_behind(marks, startKey)
    result = Object.assign(half_marks, newMarks)
  } else if (step_type == 'step_3h') {
    let newStartTime = moment(startTime).format('mm') == '00' ? moment(startTime).format('YYYY-MM-DD HH:00') : moment(startTime).add(1, 'hours').startOf('hours').format('YYYY-MM-DD HH:00')

    let newMarks = {} //修改间隔后的对象
    for (let i = startKey; i <= endKey; i++) {
      let isFlag = isThreeHours(newStartTime, ((i - startKey) * 1), 3)
      newMarks[i] = {
        key_index: i,
        style: { color: '#fff' },
        label: isFlag == 1 ? moment(newStartTime).add(((i - startKey) * 1), 'hours').format('HH') : '',
        time: moment(newStartTime).add(((i - startKey) * 1), 'hours').format('YYYY-MM-DD HH:00'),
        step_type: step_type,
        tabOption: '气候'
      }
    }

    let newNowTime = moment(nowTime).format('mm') == '00' ? moment(nowTime).startOf('hours').format('YYYY-MM-DD HH:00') : moment(nowTime).add(1, 'hours').startOf('hours').format('YYYY-MM-DD HH:00')
    target = Object.keys(newMarks).filter(item => {
      return newMarks[item].time === newNowTime
    })[0]

    let half_marks = removeObjectKeys_behind(marks, startKey)
    result = Object.assign(half_marks, newMarks)
  } else if (step_type == 'step_6h') {
    let newStartTime = moment(startTime).format('mm') == '00' ? moment(startTime).format('YYYY-MM-DD HH:00') : moment(startTime).add(1, 'hours').startOf('hours').format('YYYY-MM-DD HH:00')

    let newMarks = {} //修改间隔后的对象
    for (let i = startKey; i <= endKey; i++) {
      let isFlag = isThreeHours(newStartTime, ((i - startKey) * 1), 6)
      newMarks[i] = {
        key_index: i,
        style: { color: '#fff' },
        label: isFlag == 1 ? moment(newStartTime).add(((i - startKey) * 1), 'hours').format('HH') : '',
        time: moment(newStartTime).add(((i - startKey) * 1), 'hours').format('YYYY-MM-DD HH:00'),
        step_type: step_type,
        tabOption: '气候'
      }
    }
    let newNowTime = moment(nowTime).format('mm') == '00' ? moment(nowTime).startOf('hours').format('YYYY-MM-DD HH:00') : moment(nowTime).add(1, 'hours').startOf('hours').format('YYYY-MM-DD HH:00')
    target = Object.keys(newMarks).filter(item => {
      return newMarks[item].time === newNowTime
    })[0]

    let half_marks = removeObjectKeys_behind(marks, startKey)
    result = Object.assign(half_marks, newMarks)
  } else if (step_type == 'step_12h') {
    let newStartTime = moment(startTime).format('mm') == '00' ? moment(startTime).format('YYYY-MM-DD HH:00') : moment(startTime).add(1, 'hours').startOf('hours').format('YYYY-MM-DD HH:00')

    let newMarks = {} //修改间隔后的对象
    for (let i = startKey; i <= endKey; i++) {
      let isFlag = isThreeHours(newStartTime, ((i - startKey) * 1), 12)
      newMarks[i] = {
        key_index: i,
        style: { color: '#fff' },
        label: isFlag == 1 ? moment(newStartTime).add(((i - startKey) * 1), 'hours').format('HH') : '',
        time: moment(newStartTime).add(((i - startKey) * 1), 'hours').format('YYYY-MM-DD HH:00'),
        step_type: step_type,
        tabOption: '气候'
      }
    }
    let newNowTime = moment(nowTime).format('mm') == '00' ? moment(nowTime).startOf('hours').format('YYYY-MM-DD HH:00') : moment(nowTime).add(1, 'hours').startOf('hours').format('YYYY-MM-DD HH:00')
    target = Object.keys(newMarks).filter(item => {
      return newMarks[item].time === newNowTime
    })[0]

    let half_marks = removeObjectKeys_behind(marks, startKey)
    result = Object.assign(half_marks, newMarks)
  } else if (step_type == 'step_24h') {
    let newStartTime = moment(startTime).format('mm') == '00' ? moment(startTime).format('YYYY-MM-DD HH:00') : moment(startTime).add(1, 'hours').startOf('hours').format('YYYY-MM-DD HH:00')

    let newMarks = {} //修改间隔后的对象
    for (let i = startKey; i <= endKey; i++) {
      newMarks[i] = {
        key_index: i,
        style: { color: '#fff' },
        label: getLabel_24h(moment(newStartTime).add(((i - startKey) * 1), 'hours')),
        time: moment(newStartTime).add(((i - startKey) * 1), 'hours').format('YYYY-MM-DD HH:00'),
        step_type: step_type,
        tabOption: '气候'
      }
    }

    let newNowTime = moment(nowTime).format('mm') == '00' ? moment(nowTime).startOf('hours').format('YYYY-MM-DD HH:00') : moment(nowTime).add(1, 'hours').startOf('hours').format('YYYY-MM-DD HH:00')
    target = Object.keys(newMarks).filter(item => {
      return newMarks[item].time === newNowTime
    })[0]

    let half_marks = removeObjectKeys_behind(marks, startKey)
    result = Object.assign(half_marks, newMarks)
  } else if (step_type == 'step_10days') {
    let newStartTime = moment(startTime).startOf('day').format('YYYY-MM-DD')

    let newMarks = {} //修改间隔后的对象
    for (let i = startKey; i <= endKey; i++) {
      newMarks[i] = {
        key_index: i,
        style: { color: '#fff' },
        label: getLabel_fivedays(moment(newStartTime).add(((i - startKey) * 1), 'days'), 10),
        time: moment(newStartTime).add(((i - startKey) * 1), 'days').format('YYYY-MM-DD'),
        step_type: step_type,
        tabOption: '气候'
      }
    }
    let day_new = moment(nowTime).format('YYYY-MM-DD')
    target = Object.keys(newMarks).filter(item => {
      return newMarks[item].time === day_new
    })[0]

    let half_marks = removeObjectKeys_behind(marks, startKey)
    result = Object.assign(half_marks, newMarks)
  } else if (step_type == 'step_month') {
    let newStartTime = moment(startTime).startOf('day').format('YYYY-MM-DD')

    let newMarks = {} //修改间隔后的对象
    for (let i = startKey; i <= endKey; i++) {
      newMarks[i] = {
        key_index: i,
        style: { color: '#fff' },
        label: getLabel_fivedays(moment(newStartTime).add(((i - startKey) * 1), 'days'), 5),
        time: moment(newStartTime).add(((i - startKey) * 1), 'days').format('YYYY-MM-DD'),
        step_type: step_type,
        tabOption: '气候'
      }
    }
    let day_new = moment(nowTime).format('YYYY-MM-DD')
    target = Object.keys(newMarks).filter(item => {
      return newMarks[item].time === day_new
    })[0]

    let half_marks = removeObjectKeys_behind(marks, startKey)
    result = Object.assign(half_marks, newMarks)
  } else if (step_type == 'step_season') {
    let newStartTime = moment(startTime).startOf('day').format('YYYY-MM-DD')

    let newMarks = {} //修改间隔后的对象
    for (let i = startKey; i <= endKey; i++) {
      newMarks[i] = {
        key_index: i,
        style: { color: '#fff' },
        label: getLabel_fivedays(moment(newStartTime).add(((i - startKey) * 1), 'days'), 15),
        time: moment(newStartTime).add(((i - startKey) * 1), 'days').format('YYYY-MM-DD'),
        step_type: step_type,
        tabOption: '气候'
      }
    }
    let day_new = moment(nowTime).format('YYYY-MM-DD')
    target = Object.keys(newMarks).filter(item => {
      return newMarks[item].time === day_new
    })[0]

    let half_marks = removeObjectKeys_behind(marks, startKey)
    result = Object.assign(half_marks, newMarks)
  }

  return [result, Number(target)]
}

//计算两个时间区间内 有多少个 6min/10min/1h/3h/6h/12h/24h
export function calcStepsCount (startTime, endTime, step_type) {
  let startTimeValue = moment(startTime).valueOf()
  let endTimeValue = moment(endTime).valueOf()
  let diff = endTimeValue - startTimeValue
  let stepValue = 0
  if (step_type == 'step_6min') {
    stepValue = 360000
  } else if (step_type == 'step_10min') {
    stepValue = 600000
  } else if (step_type == 'step_1h') {
    stepValue = 3600000
  } else if (step_type == 'step_3h') {
    stepValue = 10800000
  } else if (step_type == 'step_6h') {
    stepValue = 21600000
  } else if (step_type == 'step_12h') {
    stepValue = 43200000
  } else if (step_type == 'step_24h') {
    stepValue = 86400000
  }
  return Math.floor(diff / stepValue)
}

//将对象重新排序
export function adjustObjectKeys (marks, newKey) {
  let newObject = {};
  let newKeyOffset = newKey
  Object.keys(marks).forEach(key => {
    newObject[newKeyOffset] = marks[key];
    newObject[newKeyOffset].key_index = newKeyOffset
    newKeyOffset += 1; // 增加新键值
  })
  return newObject;
}

//切换tab，自适应间隔选项
export function changeStepArr (tabOption) {
  let stepArr = []

  if (tabOption == '历史') {
    stepArr = [
      {
        value: 'step_6min',
        label: '6min',
      },
      {
        value: 'step_10min',
        label: '10min',
      },
      {
        value: 'step_1h',
        label: '1h',
      },
      {
        value: 'step_3h',
        label: '3h',
      },
      {
        value: 'step_6h',
        label: '6h',
      },
      { value: 'step_12h', label: '12h' },
      {
        value: 'step_24h',
        label: '24h',
      },
      {
        value: 'step_10days',
        label: '逐旬',
      },
      {
        value: 'step_month',
        label: '逐月',
      },
      {
        value: 'step_season',
        label: '逐季',
      },]
  } else if (tabOption == '短临') {
    stepArr = [
      {
        value: 'step_6min',
        label: '6min',
      },
      {
        value: 'step_10min',
        label: '10min',
      },
      {
        value: 'step_1h',
        label: '1h',
      },
    ]
  } else if (tabOption == '短期') {
    stepArr = [
      {
        value: 'step_6min',
        label: '6min',
      },
      {
        value: 'step_10min',
        label: '10min',
      },
      {
        value: 'step_1h',
        label: '1h',
      },
      {
        value: 'step_3h',
        label: '3h',
      },
      {
        value: 'step_6h',
        label: '6h',
      },
      { value: 'step_12h', label: '12h' },
    ]
  } else if (tabOption == '气候') {
    stepArr = [
      {
        value: 'step_6min',
        label: '6min',
      },
      {
        value: 'step_10min',
        label: '10min',
      },
      {
        value: 'step_1h',
        label: '1h',
      },
      {
        value: 'step_3h',
        label: '3h',
      },
      {
        value: 'step_6h',
        label: '6h',
      },
      { value: 'step_12h', label: '12h' },
      {
        value: 'step_24h',
        label: '24h',
      },
      {
        value: 'step_10days',
        label: '逐旬',
      },
      {
        value: 'step_month',
        label: '逐月',
      },
      {
        value: 'step_season',
        label: '逐季',
      },]
  } else {
    stepArr = [
      {
        value: 'step_6min',
        label: '6min',
      },
      {
        value: 'step_10min',
        label: '10min',
      },
      {
        value: 'step_1h',
        label: '1h',
      },
      {
        value: 'step_3h',
        label: '3h',
      },
      {
        value: 'step_6h',
        label: '6h',
      },
      { value: 'step_12h', label: '12h' },
      {
        value: 'step_24h',
        label: '24h',
      },
    ]
  }

  return stepArr
}

//是否为 3h/6h/12h的倍数
function isThreeHours (startTime, hoursToAdd, num) {
  // 创建初始日期时间对象
  let initialDateTime = moment(startTime, 'YYYY-MM-DD HH:mm:ss');
  // 加上指定的分钟数
  let newDateTime = initialDateTime.add(hoursToAdd, 'hours');
  //判断小时数是否为6/12的倍数
  let hours = Number(moment(newDateTime).format('HH')) % num

  return hours == 0 ? 1 : 0
}

//计算两个数的平均值
function getMiddleInteger (a, b) {
  let middle = (a + b) / 2;
  // 如果平均值不是整数，则向下取整
  if (middle !== Math.floor(middle)) {
    middle = Math.floor(middle);
  }
  return middle;
}

/* ---------- 标签函数 ---------- */
//获取实况的橙色标签
export function getNowPosition (min, max, marks) {
  let nowIndex = Number(Object.keys(marks).filter(key => {
    return marks[key].tabOption == '实况'
  })[0])

  let flag = false
  let position
  if (nowIndex >= min && nowIndex <= max) {
    flag = true
    position = ((nowIndex - min) / 200) * 100
  } else {
    flag = false
    position = 0
  }

  return [flag, position]
}

//获取长刻度线
export function getStepLinePosition (min, max, marks, tabOption) {
  let stepIndex
  let flag = 'none'
  let position = 0

  if (tabOption == '临近') {
    stepIndex = Number(Object.keys(marks).filter(key => {
      return marks[key].tabOption == '短临'
    })[0])
    if (stepIndex >= min && stepIndex <= max) {
      flag = 'block'
      position = ((stepIndex - min) / 200) * 100
    } else {
      flag = 'none'
      position = 0
    }
  } else if (tabOption == '短时') {
    let startIndex = Number(Object.keys(marks).filter(key => {
      return marks[key].tabOption == '短临'
    })[0])
    let startTime = marks[startIndex] ? marks[startIndex].time : moment()
    let endTime = moment(startTime).add(2, 'hours').format('YYYY-MM-DD HH:mm')
    let endArr = Object.values(marks).filter(item => {
      return item.time == endTime
    })
    let endIndex = endArr.length > 0 ? endArr[0].key_index : NaN
    if (endIndex >= min && endIndex <= max) {
      flag = 'block'
      position = ((endIndex - min) / 200) * 100
    } else {
      flag = 'none'
      position = 0
    }
  } else {
    stepIndex = Number(Object.keys(marks).filter(key => {
      return marks[key].tabOption == tabOption
    })[0])
    if (stepIndex >= min && stepIndex <= max) {
      flag = 'block'
      position = ((stepIndex - min) / 200) * 100
    } else {
      flag = 'none'
      position = 0
    }
  }
  return [flag, position]
}

//获取tag标签
export function getTagPosition (min, max, marks, tabOption) {
  let stepIndex
  let flag = 'none'
  let position = 0
  let text = ''

  if (tabOption == '历史') {
    stepIndex = 0
    if (stepIndex >= min && stepIndex <= max) {
      flag = 'block'
      position = ((stepIndex - min) / 200) * 100
    } else {
      flag = 'none'
      position = 0
    }
  } else if (tabOption == '临近') {
    stepIndex = Number(Object.keys(marks).filter(key => {
      return marks[key].tabOption == '短临'
    })[0])
    if (stepIndex >= min && stepIndex <= max) {
      flag = 'block'
      position = ((stepIndex - min) / 200) * 100
    } else {
      flag = 'none'
      position = 0
    }
  } else if (tabOption == '短时') {
    let startIndex = Number(Object.keys(marks).filter(key => {
      return marks[key].tabOption == '短临'
    })[0])
    let startTime = marks[startIndex] ? marks[startIndex].time : moment()
    let endTime = moment(startTime).add(2, 'hours').format('YYYY-MM-DD HH:mm')
    let endArr = Object.values(marks).filter(item => {
      return item.time == endTime
    })
    let endIndex = endArr.length > 0 ? endArr[0].key_index : NaN
    if (endIndex >= min && endIndex <= max) {
      flag = 'block'
      position = ((endIndex - min) / 200) * 100
    } else {
      flag = 'none'
      position = 0
    }
  } else {
    stepIndex = Number(Object.keys(marks).filter(key => {
      return marks[key].tabOption == tabOption
    })[0])
    if (stepIndex >= min && stepIndex <= max) {
      flag = 'block'
      position = ((stepIndex - min) / 200) * 100
    } else {
      flag = 'none'
      position = 0
    }
  }

  return [flag, position, text]
}

export function getTagStepType (marks, tabOption) {
  let context = ''
  if (tabOption == '历史') {
    let keys = Object.keys(marks).filter(key => {
      return marks[key].tabOption == '历史'
    })[0]
    if (keys) {
      context = getTagText(marks[keys].step_type)
    }
  } else if (tabOption == '临近') {
    let keys = Object.keys(marks).filter(key => {
      return marks[key].tabOption == '短临'
    })[0]
    if (keys) {
      context = getTagText(marks[keys].step_type)
    }
  } else if (tabOption == '短时') {
    let keys = Object.keys(marks).filter(key => {
      return marks[key].tabOption == '短临'
    })[0]
    if (keys) {
      context = getTagText(marks[keys].step_type)
    }
  } else {
    let keys = Object.keys(marks).filter(key => {
      return marks[key].tabOption == tabOption
    })[0]
    if (keys) {
      context = getTagText(marks[keys].step_type)
    }
  }
  return context
}

//根据间隔返回tag标签上的内容
export function getTagText (step_type) {
  let text = ''
  if (step_type == 'step_6min') {
    text = '6分钟'
  } else if (step_type == 'step_10min') {
    text = '10分钟'
  } else if (step_type == 'step_1h') {
    text = '1小时'
  } else if (step_type == 'step_3h') {
    text = '3小时'
  } else if (step_type == 'step_6h') {
    text = '6小时'
  } else if (step_type == 'step_12h') {
    text = '12小时'
  } else if (step_type == 'step_24h') {
    text = '24小时'
  } else if (step_type == 'step_10days') {
    text = '10天'
  } else if (step_type == 'step_month') {
    text = '月'
  } else if (step_type == 'step_season') {
    text = '季'
  }
  return text
}
